﻿using ConfExpert.Utility;
using DevExpress.XtraEditors.Repository;
using DevTeam;
using System.Data;


namespace ConfExpert.Forms.Depo
{
    public partial class DepoStokHareketler : XPopupForm
    {
        int ProductId;
        public DepoStokHareketler(int _ProductId)
        {
            InitializeComponent();

            ProductId = _ProductId;
            this.Text = "Stok Hareketleri";
            gv.OptionsView.RowAutoHeight = true;
            gv.RowHeight = 28;

            gv.Init("GetHareket", ProductId);

            DataRow dr = AppSession.Lookups.Tables["V_Kumas"].Rows.Find(ProductId);
            if (dr != null)
            {
                txtInfo.Caption = dr["Name"].ToString();
                gv.SetCaptions("AtelyeId:Geliş Yeri");
                gleProduct.Edit.Assign(RI(Rp.V_Kumas));
                gv.Columns["Toplar"].Width = 200;
            }
            else
            {
                DataRow drTela = AppSession.Lookups.Tables["Tela"].Rows.Find(ProductId);
                if (drTela != null)
                {
                    txtInfo.Caption = drTela["Name"].ToString();
                    gv.SetCaptions("GelisYeriId:Geliş Yeri");
                    gleProduct.Edit.Assign(RI(Rp.Tela));
                    gv.Columns["GelisYeriId"].ColumnEdit = RI(Rp.TelaVendor);
                }
            }

            gv.SetCaptions("CikisYeriId:Çıkış Yeri", "OrderRef:Order Ref.", "CikanMiktar:Çıkan Metraj", "GelenMiktar:Giren Metraj");

            gv.FormatAsDate("Tarih");
            gv.FormatAsNumber(1, "CikanMiktar", "GelenMiktar");
            gv.AddSummary("GelenMiktar", "CikanMiktar");
            gv.MakeColumnInvisible("ProductId");
            gv.SortInfo.Add(gv.Columns["Tarih"], DevExpress.Data.ColumnSortOrder.Ascending);

            gv.ShowFindPanel();
        }

        private void DepoStokHareketler_Load(object sender, System.EventArgs e)
        {

            //GleExtend(gleProduct);
            ((RepositoryItemGridLookUpEdit)gleProduct.Edit).TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
            gleProduct.Edit.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.Default;
            gleProduct.EditValueChanged += new System.EventHandler(gleProduct_EditValueChanged);
            gv.BestFitColumns();
        }

        void gleProduct_EditValueChanged(object sender, System.EventArgs e)
        {
            int ProductId = gleProduct.EditValue.ToInt();
            gv.RefreshDataSource(true, "GetHareket", ProductId);
            txtInfo.Caption = string.Empty;
            gv.BestFitColumns();
            gv.Columns["Toplar"].Width = 200;
        }
    }
}
